package com.example.javaairportflightanalysis.dao;


import com.example.javaairportflightanalysis.domin.userpojo.Permission;
import com.example.javaairportflightanalysis.domin.userpojo.Role;
import com.example.javaairportflightanalysis.domin.userpojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * (Permission)表数据库访问层
 *
 */
@Mapper
public interface PermissionMapper  {

    @Select("SELECT distinct TP.keyword\n" +
            "FROM t_permission TP\n" +
            "INNER JOIN t_role_permission TRP ON TP.id = TRP.permission_id\n" +
            "INNER JOIN t_user_role TUR ON TRP.role_id = TUR.role_id\n" +
            "WHERE TUR.user_id = #{id};")
    List<String> getPermissions(Integer id);

    @Select("select * from t_permission")
    List<Permission> findAllPermission();

    @Insert("insert into t_permission values(#{name},#{keyword},#{description})")
    void addPermission(Permission permission);

    @Delete("delete from t_permission where id=#{id}")
    void deletePermission(Integer id);

    @Update("update t_permission set name=#{name},keyword=#{keyword},description=#{description} where id=#{id}")
    void updatePermission(Permission permission);
}

